package com.tnxst.phexamination.activity;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.SavedStateViewModelFactory;
import androidx.lifecycle.ViewModelProvider;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.tnxst.phexamination.R;
import com.tnxst.phexamination.databinding.ActivityAddDoorRecordBinding;
import com.tnxst.phexamination.dto.SignDTO;
import com.tnxst.phexamination.fragment.RecordTcmHealthElderlyFragment;
import com.tnxst.phexamination.fragment.SignFragment;
import com.tnxst.phexamination.fragment.follow.DiabetesFollowFragment;
import com.tnxst.phexamination.fragment.follow.FilingPhthisisFragment;
import com.tnxst.phexamination.fragment.follow.FirstPhthisisFragment;
import com.tnxst.phexamination.fragment.follow.HypertensionFollowFragment;
import com.tnxst.phexamination.fragment.follow.NewbornFamilyFollowFragment;
import com.tnxst.phexamination.fragment.follow.PhthisisFollowFragment;
import com.tnxst.phexamination.utils.Utils;
import com.tnxst.phexamination.viewmodel.GlobalViewModel;

/**
 * 添加随访记录
 */
public class AddDoorRecordActivity extends BaseActivity implements View.OnClickListener{

    private ActivityAddDoorRecordBinding binding;

    private GlobalViewModel viewModel;

    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewModel = new ViewModelProvider(this, new SavedStateViewModelFactory(getApplication(), this)).get(GlobalViewModel.class);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_add_door_record);
        binding.setAddDoorRecord(viewModel);
        binding.setLifecycleOwner(this);
        context = this;
        initView();
    }

    private void initView() {
        binding.textView344.setOnClickListener(this);
        binding.textView1.setOnClickListener(this);
        binding.textView2.setOnClickListener(this);
        binding.textView3.setOnClickListener(this);
        binding.textView4.setOnClickListener(this);
        binding.textView5.setOnClickListener(this);
        binding.textView6.setOnClickListener(this);
        binding.textView7.setOnClickListener(this);
        binding.textView8.setOnClickListener(this);
        binding.textView10.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id){
            case R.id.textView344:
                finish();
                break;
            case R.id.textView1:
                Utils.Toast(context,"该功能尚未开放！");
                break;
            case R.id.textView2:
                final AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
                View view = View.inflate(context, R.layout.add_tb_follow_dialog, null);
                alertDialog
                        .setView(view)
                        .create();
                AlertDialog show = alertDialog.show();
                show.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
                show.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
                TextView firstFollow = show.findViewById(R.id.textView6);
                TextView follow = show.findViewById(R.id.textView7);
                TextView filing = show.findViewById(R.id.textView13);
                Button button = show.findViewById(R.id.button2);
                firstFollow.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        showFragment(new FirstPhthisisFragment());
                        show.dismiss();
                    }
                });

                follow.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        showFragment(new PhthisisFollowFragment());
                        show.dismiss();
                    }
                });

                filing.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        showFragment(new FilingPhthisisFragment());
                        show.dismiss();
                    }
                });

                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        show.dismiss();
                    }
                });
                break;
            case R.id.textView3:
                showFragment(new HypertensionFollowFragment());
                break;
            case R.id.textView4:
                Utils.Toast(context,"该功能尚未开放！");
                break;
            case R.id.textView5:
//                startActivity(new Intent(this,NewbornFamilyFollowActivity.class));
                showFragment(new NewbornFamilyFollowFragment());
                finish();
                break;
            case R.id.textView6:
                showFragment(new DiabetesFollowFragment());
                break;
            case R.id.textView7://新生儿随访记录
               startActivity(new Intent(this,NewbornFamilyFollowActivity.class));
               finish();
                break;
            case R.id.textView8:
                Utils.Toast(context,"该功能尚未开放！");
                break;
            case R.id.textView10:
//                Utils.Toast(context,"该功能尚未开放！");
                startActivity(new Intent(this,ThreeToSixYearFollowActivity.class));
                finish();
                break;
        }

    }

    private void showFragment(Fragment fragment) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.setCustomAnimations(R.anim.fragment_slide_up, 0);
        ft.replace(android.R.id.content, fragment);
        ft.show(fragment);
        ft.commitAllowingStateLoss();
    }

}